// remark.js
var app = getApp(); 
var utils=require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    logoSrc: "/img/ico/pencil.png",
    curPage:1,
    pageCount:10,
    curPage2:1,
    pageCount2:10,
    hasMoreData: true,
    hasMoreData2: true,
    parentReply:[],
    replyList:[]
  },
  remarkTap: function(e){
    console.log(e.currentTarget.dataset.id);
    this.setData({
      currentTab: e.currentTarget.dataset.id
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var curPage = that.data.curPage;  
    var curPage2 = that.data.curPage2;
    wx.request({
      url: app.globalData.http + "selectReplyComments.do",
      header: {
          'content-type': 'application/json'
      },
      data: {
        curPage : curPage,
        reply : "0",
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
      },
      success: function(res){
        console.log("评语管理==家长回复===",res.data);
        var code = res.data.code;
        if(code == 100){
          var list = res.data.data.subList;
          var length = list.length;
          for(var i = 0; i < length; i++){
            list[i].updateDate  =utils.formatTime( new Date(list[i].updateDate ));
          }
          that.setData({
            parentReply: list,
            curPage: curPage+1,
            pageCount: res.data.data.pageCount,
          })
        }
        if(code == 200){
          that.setData({
            codeTxt1: "暂时没有数据"
          })
        }
        if(code == 300){
          that.setData({
            codeTxt1: "哇哦~接口异常"
          })
        }
      }
    });
    wx.request({
      url: app.globalData.http + "selectReplyComments.do",
      header: {
          'content-type': 'application/json'
      },
      data: {
        curPage : curPage2,
        reply: "1",
        busId: parseInt(wx.getStorageSync("busId")),
        employeesId: parseInt(wx.getStorageSync("employeesId")),
        schoolId: parseInt(wx.getStorageSync("schoolId"))
      },
      success: function(res){
        console.log("评语管理==评语记录===",res.data);
        var code = res.data.code;
        if(code == 100){
          var list = res.data.data.subList;
          var length = list.length;
          for(var i = 0; i < length; i++){
            list[i].updateDate  =utils.formatTime( new Date(list[i].updateDate ));
          } 
          that.setData({
            replyList: list,
            curPage2: curPage2+1,
            pageCount2: res.data.data.pageCount,
          })
        }
        if(code == 200){
          that.setData({
            codeTxt2: "暂无数据"
          })
        }
        if(code == 300){
          that.setData({
            codeTxt2: "哇哦~接口异常"
          })
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  var that = this;
    var currentTab = that.data.currentTab;
    var hasMoreData = that.data.hasMoreData;
    var hasMoreData2 = that.data.hasMoreData2;
    var url = app.globalData.http + "selectReplyComments.do";
    if(currentTab == 0){
      var curPage = that.data.curPage;
      if(hasMoreData == true){
        that.setData({
          hasMoreData: false
        })
      }

      wx.request({
        url: url,
        header: {
            'content-type': 'application/json'
        },
        data: {
          curPage: curPage,
          nowIntention :"0",
          busId: parseInt(wx.getStorageSync("busId")),
          employeesId: parseInt(wx.getStorageSync("employeesId")),
          schoolId: parseInt(wx.getStorageSync("schoolId"))
        },
        success: function(res){
          console.log("分页请求返回的数据==",res.data);
          var pageCount = res.data.data.pageCount;
          var code = res.data.code;
          if(code == 100){
            var list = res.data.data.subList;
            var length = list.length;
            for(var i = 0; i < length; i++){
              list[i].updateDate  =utils.formatTime( new Date(list[i].updateDate ));
            } 

            if(curPage > pageCount){
              that.setData({
                hasMoreData: false
              });
              return
            }
            that.setData({
              parentReply: that.data.parentReply.concat(list),
              curPage: curPage+1,
              hasMoreData: true
            });
            console.log("curpage===",that.data.curPage);
          }
          else{
            that.setData({
              hasMoreData: false
            })
            return
          }
          
        }
      })
    }


    if(currentTab == 1){
      var curPage2 = that.data.curPage2;
      console.log("111111111111111111");
      if(hasMoreData2 == true){
        that.setData({
          hasMoreData2: false
        })
      }

      wx.request({
        url: url,
        header: {
            'content-type': 'application/json'
        },
        data: {
          curPage: curPage2,
          nowIntention :"1",
          busId: parseInt(wx.getStorageSync("busId")),
          employeesId: parseInt(wx.getStorageSync("employeesId")),
          schoolId: parseInt(wx.getStorageSync("schoolId"))
        },
        success: function(res){
          console.log("分页请求返回的数据==",res.data);
          var pageCount2 = res.data.data.pageCount;
          var code = res.data.code;
          if(code == 100){
            var list = res.data.data.subList;
            var length = list.length;
            for(var i = 0; i < length; i++){
              list[i].updateDate  =utils.formatTime( new Date(list[i].updateDate ));
            } 
            if(curPage2 > pageCount2){
              that.setData({
                hasMoreData2: false
              });
              return
            }
            that.setData({
              replyList: that.data.replyList.concat(list),
              curPage2: curPage2+1,
              hasMoreData2: true
            });
            console.log("curpage===",that.data.curPage);
          }
          else{
            that.setData({
              hasMoreData2: false
            })
            return
          }
          
        }
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})